package util;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 得到本机的 IP 地址
 * 
 * @author Jason
 * 
 */
public class Local {

	/**
	 * 得到一组 ip
	 * 
	 * @return InetAddress
	 */
	public InetAddress[] getLocalIPs() {
		InetAddress[] mArLocalIP = null;
		if (mArLocalIP == null) {
			try {
				mArLocalIP = InetAddress.getAllByName(InetAddress
						.getLocalHost().getHostName());
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
		}
		return mArLocalIP;
	}

	/**
	 * 得到 ip
	 * 
	 * @return String
	 */
	public String getLocalIP() {
			try {
				return InetAddress.getLocalHost().getHostAddress();
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
	}

}
